package com.loper7.base.utils;

import android.annotation.TargetApi;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.view.View;

/**
 * Created by lenovo on 2018/4/25.
 */

public class EasyShapeUtils {
    /**
     * 设置shape倒角和颜色
     * @param view
     * @param solidColor
     * @param corner
     */
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public static void setShapeCorner_Color(View view, int solidColor, float corner){
        if(view == null){
            return;
        }
        GradientDrawable drawable=new GradientDrawable();
        drawable.setCornerRadius(DisplayUtil.dip2px(view.getContext(),corner));//设置4个角的弧度
        drawable.setColor(solidColor);// 设置颜色
        view.setBackground(drawable);
    }

    /**
     * 设置shape倒角 颜色 和描边颜色和大小
     * @param view
     * @param solidColor
     * @param corner
     */
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public static void setShapeCorner_Color_Stroke(View view, int solidColor, float corner, int strokeColor, int strokeWidth){
        if(view == null){
            return;
        }
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setColor(solidColor);
        gradientDrawable.setCornerRadius(DisplayUtil.dip2px(view.getContext(),corner));
        gradientDrawable.setStroke(strokeWidth, strokeColor);
        view.setBackground(gradientDrawable);
    }


}
